//useState实现一个计数器按钮

import { useState } from "react"

function App() {
  //1.调用一个useState添加一个状态变量
  //count 状态变量
  //setCount 修改状态变量的方法
  const [ count, setCount ]  = useState(0)

  //2.点击事件回调
  const handleClick = () =>{
    //作用:1.用传入的新值修改count
    // 2.重新使用新的count修改UI
    setCount(count + 1)
  }

  const [ form, setForm ] = useState({ name:'jack' })
  const handleSetFromClick = (name) =>{
    setForm({
      ...form,
      name: name
    })
  }
  return (
    <div className="App">
      <button onClick={ handleClick }>{ count }</button>
      <button onClick={ () => handleSetFromClick('john') }>{ form.name }</button>
    </div>
  );
}

export default App;
